@echo off
cd /d "%~dp0"
:: 设置node环境变量
set PATH=%PATH%;./node-v20.9.0-win-x64/
:: 检查是否以管理员身份运行（全局安装可能需要权限）
NET SESSION >nul 2>&1
if %ERRORLEVEL% EQU 0 (
    echo checking admin privileges
) else (
    echo please run this script with admin privileges.
    pause
    exit /b 1
)

:: 检查 cnpm 是否已安装
where cnpm >nul 2>&1
if %ERRORLEVEL% EQU 0 (
    echo cnpm has intstalled.
) else (
    echo cnpm not install, now installing cnpm...
    npm install -g cnpm --registry=https://registry.npmmirror.com
    if %ERRORLEVEL% NEQ 0 (
        echo install  failed  check  your  network.
        pause
        exit /b 1
    )
    echo cnpm install success.
)

:: 使用 cnpm 安装依赖（--production=false 安装所有依赖）
echo now install project dependencies...
call cnpm install --production=false
if %ERRORLEVEL% NEQ 0 (
    echo failed check it.
    pause
    exit /b 1
)

:: 运行 electron:build
echo now building ...
npm run electron:build
if %ERRORLEVEL% NEQ 0 (
    echo buidling failed.
    pause
    exit /b 1
)

echo buidling success!
pause